from flask import Flask, jsonify, request
import os

app = Flask(__name__)
customers=[
    "北京科技有限公司",
    "上海仪器设备有限公司",
    "广州测试技术有限公司",
    "深圳测试有限公司",
]

@app.route('/api/search_customers', methods=['GET'])
def search_customers():
    term = request.args.get('term', '').lower()
    print(f"Received search term: {term}")
    
    # 如果文件读取失败，使用默认数据
    if not customers:
        results = [
            "北京科技有限公司",
            "上海仪器设备有限公司",
            
        ]
    else:
        results = [name for name in customers if term in name.lower()]
    
    print(f"Returning results: {results}")
    return jsonify(results)

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=5000)